package app.database.friendlist;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;


public class FriendListDBhelper extends SQLiteOpenHelper{
	private static final String CREATE_TABLE="create table "+
	Constants.TABLE_NAME + " (" +
	Constants.FRIEND_NAME+" text not null, "+
	Constants.EMAIL_NAME+" text primary key, "+
	Constants.NOTIFICATION_NAME+" text, "+
	Constants.DATE_NAME +" text);";

	private static final String CREATE_TABLE1="create table "+
	Constants.TABLE_NAME1 + " (" +
	Constants.FRIEND_NAME+" text not null, "+
	Constants.EMAIL_NAME+" text primary key, "+
	Constants.NOTIFICATION_NAME+" text, "+
	Constants.DATE_NAME +" text);";
	
	public FriendListDBhelper(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase arg0) {
		// TODO Auto-generated method stub
		Log.v("FriendListDBhelper onCreate", "Creating all the tables");
		try {
			arg0.execSQL(CREATE_TABLE);
			arg0.execSQL(CREATE_TABLE1);
		}catch(SQLiteException ex){
			Log.v("Create table exception", ex.getMessage());
		}
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub
		Log.w("TaskDBAdapter", "Upgrading from version "+arg1+" to "+arg2+", which will destroy all old data");
		arg0.execSQL("drop table if exists "+Constants.TABLE_NAME);
		arg0.execSQL("drop table if exists "+Constants.TABLE_NAME1);
		onCreate(arg0);
	}
	
	
}
